package com.java.java基础.文件操作;

import java.io.FileInputStream;
import java.io.FileOutputStream;

/**
 * 文件拷贝
 */
// 完成文件拷贝 '将c盘的1332803.png拷贝到d盘的BaiduNetdiskDownload'
// 1. 创建源 2. 创建目的地 3. 输入流 4. 输出流 5. 释放资源
// 完成程序时应该是读取部分再写入部分-for循环
public class FileCopy {
    public static void main(String[] args) {
        FileCopy fileCopy = new FileCopy();
        FileInputStream fileInputStream = null;
        FileOutputStream fileOutputStream = null;
        try {
            fileInputStream = new FileInputStream("C:\\Users\\DDN\\Pictures\\桌面背景\\图片\\1332803.png");
            fileOutputStream = new FileOutputStream("D:\\ruoyi");
            byte[] bytes = new byte[1024];
            int read = 0;
            for (int i = 0; i < 1024; i++) {
                read = fileInputStream.read();
                fileOutputStream.write(read);
            }
            System.out.println("拷贝成功");
        }catch (Exception e){
            e.printStackTrace();
        }finally {
            try {
                if (fileInputStream != null) {
                    fileInputStream.close();
                }
                if (fileOutputStream != null){
                    fileOutputStream.close();
                }
            }catch (Exception e){
                e.printStackTrace();
            }
        }
    }


}
